<%@ include file="/common/taglibs.jsp"%>
<title><fmt:message key="menu.logConfig" /></title>
<content tag="buttons">
<probiz:iconBtn btnType="save" onclick="return fnDoSave(this);" />
<probiz:iconBtn btnType="reloadAll" onclick="resetAll()"
	btnTextKey="button.resetAll" />
<probiz:iconBtn btnType="download" onclick="fnDoAction(this, 'downloadLog')"
	btnTextKey="button.download" />
<probiz:iconBtn btnType="add" onclick="showAddNewLoggerDlg()"
	btnTextKey="log4jMgr.addButton" />
</content>

<form class="mainForm" method="post" action="${ctxPath}/tool/log4jMgr.html" >
	<div class="top clearfix">
		<ul class="tab">
			<li class="curr">
				<span><fmt:message key="menu.logConfig" /> </span>
			</li>
		</ul>
	</div>
	<div class="modify">
		<c:set var="optionalLevelArray" value="${fn:split('DEBUG,INFO,WARN,ERROR,FATAL,OFF',',')}" />
		<div class="box_01">
			<div class="top">
				<div class="cnt">
					<h3><fmt:message key="log4jMgr.tab.default"/>
					</h3>
				</div>
			</div>
			<div class="content">
				<display:table name="${logger}" cellspacing="0" cellpadding="0" uid="loggerItem"
					class="list_table" export="false" requestURI="" style="width:100%">
					<display:column style="width:40%" sortable="false" headerClass="data-table-title" titleKey="log4jMgr.pattern"
						decorator="com.probiz.estore.core.decorator.TblColumnDecorator">
				       ${loggerItem}
					</display:column>
					<display:column style="width:40%" sortable="false" headerClass="data-table-title"
						decorator="com.probiz.estore.core.decorator.TblColumnDecorator"
						titleKey="log4jMgr.currentLevel">

						<select name="${loggerItem}" id="${loggerItem}" class="selecttxt">
							<c:forEach items="${optionalLevelArray}" var="optionalLevel">
								<option value="${optionalLevel}"
									<c:if test="${currentLoggerLevel[loggerItem] == optionalLevel}">selected</c:if>>
									${optionalLevel}
								</option>
							</c:forEach>
						</select>
						<c:if test="${originalLoggerLevel[loggerItem] != currentLoggerLevel[loggerItem]}">
				(<span class="red">#</span>)
				</c:if>
					</display:column>
					<display:column sortable="false" headerClass="data-table-title"
						decorator="com.probiz.estore.core.decorator.TblColumnDecorator"
						titleKey="log4jMgr.originalSetting">
						${originalLoggerLevel[loggerItem]}
					</display:column>
				</display:table>
			</div>
		</div>
		
		<div class="box_01">
			<div class="top">
				<div class="cnt">
					<h3><fmt:message key="log4jMgr.tab.extra"/>
					</h3>
				</div>
			</div>
			<div class="content">
				<c:choose>
					<c:when test="${not empty extraLoggerList}">
						<display:table name="${extraLoggerList}" cellspacing="0" cellpadding="0" uid="extraLoggerItem"
			                 class="list_table" export="false" requestURI="" style="width:100%">
			                 <display:column style="width:40%" sortable="false" headerClass="data-table-title" titleKey="log4jMgr.pattern" decorator="com.probiz.estore.core.decorator.TblColumnDecorator">
			                 	${extraLoggerItem.pattern}
							 </display:column>
			                 <display:column style="width:40%" sortable="false" headerClass="data-table-title"
			                     decorator="com.probiz.estore.core.decorator.TblColumnDecorator" titleKey="log4jMgr.currentLevel">
			                     <select name="extra_${extraLoggerItem.pattern}" id="${extraLoggerItem.pattern}" class="selecttxt">
									<c:forEach items="${optionalLevelArray}" var="optionalLevel">
										<option value="${optionalLevel}" <c:if test="${extraLoggerItem.level == optionalLevel}">selected</c:if>>
											${optionalLevel}
										</option>
									</c:forEach>
								</select>
			                 </display:column>
			                 <display:column sortable="false" headerClass="data-table-title"
								decorator="com.probiz.estore.core.decorator.TblColumnDecorator"
								titleKey="button.delete">
								<a href="javascript:void(0)" onclick="removeLogger('${extraLoggerItem.pattern}')"><fmt:message key="button.delete"/></a>
							</display:column>
			             </display:table>
					</c:when>
					<c:otherwise>
						<fmt:message key="log4jMgr.emptyExtraLogger"/>
					</c:otherwise>
				</c:choose>
			</div>
		</div>

	</div>
</form>


<script type="text/javascript">
$j(document).ready(function(){
   __FMTExtend = {
		log4jMgr_resetAll_confirm:"<fmt:message key="log4jMgr.resetAll.confirm"/>"
	};
	$j.extend(__FMT, __FMTExtend); 	
	
   highlightTableRows("loggerItem");
   
   applyValidate($('pattern'),"required");
   applyValidate($('level'),"required");
});

//重设
function resetAll(){
	if(confirm(__FMT.log4jMgr_resetAll_confirm)){
		fnDoAction(this, 'resetAll');
	}
}

//添加新的日志等级
function addNewLogger(){
	var form=document.forms["addNewLogger"];
	if(validateForm(form)){
		form.submit();		
	}else{
		alert(__vaMsg.notPass);
	}
}
function showAddNewLoggerDlg(){
	$('pattern').value = "";
	$('level').selectedIndex = 0;
	dlgaddNewLoggerDlg_show();
}

//关闭添加新日志等级对话框
function  closeAddNewLoggerDlg(){
	dlgaddNewLoggerDlg_close();
}
//删除自定义日志
function removeLogger(pattern){
	var form=$j("form.mainForm").get(0);	
	fnAddHiddenField("pattern",pattern,form);
	fnDoAction(this, 'removeExtraLogger');
}
</script>

<fmt:message key="button.confirm" var="buttonConfirm"/>
<fmt:message key="button.cancel" var="buttonCancel"/>
<fmt:message key="log4jMgr.addNew" var="title"/>
<probiz:ui_dialog id="addNewLoggerDlg" width="500" height="150" title="${title}" buttons="'${buttonConfirm}':addNewLogger,'${buttonCancel}':closeAddNewLoggerDlg">
	<form id="addNewLogger" name="addNewLogger">
		<input type="hidden" name="doAction" value="addExtraLogger"/>
		<div>
			<table  width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
			  <tr>
			   <th height="30px" width="150" align="left"><fmt:message key="log4jMgr.pattern"/>：</th>
			    <td>
					<input type="text" id="pattern" name="pattern" value="" class="inputtxt" style="width:250px;"/>
				</td>
			  </tr>
			  <tr>
			   <th height="30px" width="150" align="left"><fmt:message key="log4jMgr.currentLevel"/>：</th>
			    <td>
					 <select name="level" id="level" class="selecttxt">
					 	<option value=""><fmt:message key="log4jMgr.level.pleaseSelect"/></option>
						<c:forEach items="${optionalLevelArray}" var="optionalLevel">
							<option value="${optionalLevel}" >
								${optionalLevel}
							</option>
						</c:forEach>
					</select>
				</td>
			  </tr>
			</table>
		</div>
	</form>
</probiz:ui_dialog>
